<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function reg(){
				//0.收集填入的信息,	非空验证
				var $receiver=receiver.value;
				var $province=province.value;
				var $city=city.value;
				var $county=county.value;
				var $address=address.value;
				var $cellphone=cellphone.value;
				var $postcode=postcode.value;
				if(!$receiver){alert("接收人姓名不能为空");return}
				if(!$province){alert("省不能为空");return}
				if(!$city){alert("市不能为空");return}
				if(!$county){alert("县不能为空");return}
				if(!$address){alert("详细地址不能为空");return}
				if(!$cellphone){alert("手机号码不能为空");return}
				if(!$postcode){alert("邮编不能为空");return}
				//1.创建xhr异步对象
				var xhr=new XMLHttpRequest();
				//4.接收响应
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4 && xhr.status==200){
						var r=xhr.responseText;
						if(r==1){
							alert("添加成功")
						}else{
							alert("添加失败")
						}
					}
				}
				//2.创建请求,打开连接
				xhr.open("POST",`/address/v1/vip_receive_address_reg`,true)
				//3.发送请求
				var formdata=`receiver=${$receiver}&province=${$province}&city=${$city}&county=${$county}&address=${$address}&cellphone=${$cellphone}&postcode=${$postcode}`;
				console.log(formdata)
				xhr.setRequestHeader("content-type","application/x-www-form-urlencoded")
				xhr.send(formdata);
			}
		</script>
	</head>
	<body>
		<input type="text" id="receiver">接收人姓名<br>
		<input type="text" id="province">省<br>
		<input type="text" id="city">市<br>
		<input type="text" id="county">县<br>
		<input type="text" id="address">详细地址<br>
		<input type="text" id="cellphone">手机号码<br>
		<input type="text" id="postcode">邮编<br>
		<button onclick="reg()">添加地址</button>
	</body>
</html>
